package com.ruoyi.demo.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import com.ruoyi.demo.domain.SakuraExp;
import com.ruoyi.demo.mapper.SakuraEmployeesMapper;
import com.ruoyi.demo.domain.SakuraEmployees;
import com.ruoyi.demo.service.ISakuraEmployeesService;

/**
 * 基本信息Service业务层处理
 * 
 * @author 蓝鲸
 * @date 2024-08-09
 */
@Service
public class SakuraEmployeesServiceImpl implements ISakuraEmployeesService 
{
    @Autowired
    private SakuraEmployeesMapper sakuraEmployeesMapper;

    /**
     * 查询基本信息
     * 
     * @param id 基本信息主键
     * @return 基本信息
     */
    @Override
    public SakuraEmployees selectSakuraEmployeesById(Long id)
    {
        return sakuraEmployeesMapper.selectSakuraEmployeesById(id);
    }

    /**
     * 查询基本信息列表
     * 
     * @param sakuraEmployees 基本信息
     * @return 基本信息
     */
    @Override
    public List<SakuraEmployees> selectSakuraEmployeesList(SakuraEmployees sakuraEmployees)
    {
        return sakuraEmployeesMapper.selectSakuraEmployeesList(sakuraEmployees);
    }

    /**
     * 新增基本信息
     * 
     * @param sakuraEmployees 基本信息
     * @return 结果
     */
    @Transactional
    @Override
    public int insertSakuraEmployees(SakuraEmployees sakuraEmployees)
    {
        int rows = sakuraEmployeesMapper.insertSakuraEmployees(sakuraEmployees);
        insertSakuraExp(sakuraEmployees);
        return rows;
    }

    /**
     * 修改基本信息
     * 
     * @param sakuraEmployees 基本信息
     * @return 结果
     */
    @Transactional
    @Override
    public int updateSakuraEmployees(SakuraEmployees sakuraEmployees)
    {
        sakuraEmployeesMapper.deleteSakuraExpByExperienceId(sakuraEmployees.getId());
        insertSakuraExp(sakuraEmployees);
        return sakuraEmployeesMapper.updateSakuraEmployees(sakuraEmployees);
    }

    /**
     * 批量删除基本信息
     * 
     * @param ids 需要删除的基本信息主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteSakuraEmployeesByIds(Long[] ids)
    {
        sakuraEmployeesMapper.deleteSakuraExpByExperienceIds(ids);
        return sakuraEmployeesMapper.deleteSakuraEmployeesByIds(ids);
    }

    /**
     * 删除基本信息信息
     * 
     * @param id 基本信息主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteSakuraEmployeesById(Long id)
    {
        sakuraEmployeesMapper.deleteSakuraExpByExperienceId(id);
        return sakuraEmployeesMapper.deleteSakuraEmployeesById(id);
    }

    /**
     * 新增${subTable.functionName}信息
     * 
     * @param sakuraEmployees 基本信息对象
     */
    public void insertSakuraExp(SakuraEmployees sakuraEmployees)
    {
        List<SakuraExp> sakuraExpList = sakuraEmployees.getSakuraExpList();
        Long id = sakuraEmployees.getId();
        if (StringUtils.isNotNull(sakuraExpList))
        {
            List<SakuraExp> list = new ArrayList<SakuraExp>();
            for (SakuraExp sakuraExp : sakuraExpList)
            {
                sakuraExp.setExperienceId(id);
                list.add(sakuraExp);
            }
            if (list.size() > 0)
            {
                sakuraEmployeesMapper.batchSakuraExp(list);
            }
        }
    }
}
